﻿using BLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;

namespace HRP.Private.Departamentos
{
    public partial class Index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Page.PreRender += new EventHandler(Page_PreRender);
        }

        void Page_PreRender(object sender, EventArgs e)
        {
            if (Session["idclient"] != null && Session["EmpresaActual"] != null)
            {
                hrp_empresas empresa = (hrp_empresas)Session["EmpresaActual"];
                departamentosTable.DataSource = Departamento_BLL.Instance.obterDepartamentosEmpresa((int)Session["idclient"], empresa.id, false, false).OrderBy(d=>d.departamento).ToList();
                departamentosTable.DataBind();
            }
        }

        public void alterarEstadoDep(Object sender, CommandEventArgs e)
        {
            int depId = 0;
            Int32.TryParse(e.CommandArgument.ToString(), out depId);
            if (depId != 0 && Session["idclient"] != null && Session["userid"]!=null)
            {
                int id_cliente = (int)Session["idclient"];
                string userId = Session["userid"].ToString();
                Departamento_BLL.Instance.AlterarEstado((int)Session["idclient"], userId, depId);
            }
        }
    }
}